class Solution {
public:
	vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
		vector<vector<int> >temp(r, vector<int>(c));
		if (mat.size() * mat[0].size() != r * c) {
			return mat;
		}
		else {
			for (int i = 0; i < mat.size() * mat[0].size(); i++) {
				temp[i / c][i % c] = mat[i / mat[0].size()][i % mat[0].size()];
			}
			return temp;
		}
	}
};
